#include <stdio.h>
#include <string.h>
 
void print_bits(short bit)
{   int i = 0;
    char bits[(sizeof(short)*4)+1];
    
    memset(bits,0,(sizeof(short)*4)+1);
    while (i<(sizeof(short)*4))
    {
        bits[((sizeof(short)*4)-1)-i] = (char)48+((bit>>i) & 0x1);
        i++;
    }
    printf("%s",bits);
}

int main(void)
{
    short i = 0xabcd;
  //1010 1011 1100 1101

  // 0xcd = int -51

    char *p = (char *) &i;
    printf("Original = %x, byte[1]=%x, byte[0]=%x\n", 0xFFFF&i, 0xFF&p[1], 0xFF&p[0]); 
    printf("Original en bits = ");
    print_bits(p[1]);
    print_bits(p[0]);
    printf("\n");
    printf("Original little  = ");
    printf("1010101111001101\n");
   if ( (p[0]&0xFF) == 0xCD )
        printf("Procesador tipo Little Endian.\n");
   else
        printf("Procesador tipo Big Endian.\n");

   return 0;
}

